package cn.fly.blog.common.dto;

import cn.fly.blog.common.rest.ResultCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * Http请求返回的统一结果
 */
@Accessors(chain = true)
@Setter
@Getter
public class Result<T> {

    private static ThreadLocal<Result> successCache = ThreadLocal.withInitial(Result::new);

    /**
     * 业务结果code
     */
    ResultCode code = ResultCode.SUCCESS;
    /**
     * 业务返回数据
     */
    T data;
    /**
     * 提示信息，包括错误场景下的主要错误信息
     */
    String msg;
    /**
     * 补充额外字段
     */
    Object extra;
    Pageable page;

    public static Result ofSuccess(Object data) {
        Result result = successCache.get();
        return result.setData(data);
    }

}
